CD		= cd
CP		= cp
RM		= rm -f
RMDIR	= rmdir
MD		= mkdir
CC		= cc
LN		= ln -s

CFLAGS		= -W -Wall -fPIC
LFLAGS		= -shared
LNKFLAGS	= -lpthread -lncursesw

LIBPATH		= lib
OBJPATH		= obj
SRCPATH		= src

VERSION		= 1

DESTDIR		= /usr
DESTLIB		= $(DESTDIR)/lib
DESTINC		= $(DESTDIR)/include/CSLP

LIBNAME		= libcslp.so.$(VERSION)
LIBLNKNAME	= libcslp.so
NAME		= $(LIBNAME)

SRCS		= $(SRCPATH)/Clock.c $(SRCPATH)/Colors.c $(SRCPATH)/Cursor.c $(SRCPATH)/Error.c $(SRCPATH)/Init.c $(SRCPATH)/Input.c $(SRCPATH)/Mutex.c $(SRCPATH)/Network.c $(SRCPATH)/System.c $(SRCPATH)/TCP.c $(SRCPATH)/UDP.c
HEADERS		= $(SRCS:.c=.h) $(SRCPATH)/CSLP.h $(SRCPATH)/dll.h
OBJS		= $(SRCS:.c=.o)

###########################################################
#	Début des instructions
###########################################################

all			: $(NAME)

$(NAME)			: $(OBJS)
	$(CC) $(OBJS) -o $(NAME) $(LNKFLAGS) $(LFLAGS)

.PHONY			: clean mrproper

clean			:
	$(RM) -f $(OBJS)

###########################################################
#	instructions d'installation
###########################################################
install			: all uninstall $(DESTINC) $(HEADERS)
	$(CP) $(NAME) $(DESTLIB)
	$(CP) $(HEADERS) $(DESTINC)
	$(CD) $(DESTLIB) && $(LN) $(LIBNAME) $(LIBLNKNAME)

$(DESTINC)		:
	$(MD) $(DESTINC)

uninstall		:
	$(RM) $(DESTLIB)/$(LIBNAME) $(DESTLIB)/$(LIBLNKNAME)
	$(RM) $(DESTINC)/*.h
	-$(RMDIR) $(DESTINC)
